//
//  ViewController.m
//  DNS拦截
//
//  Created by Xie Wei on 2019/7/29.
//  Copyright © 2019 Xie Wei. All rights reserved.
//

#import "ViewController.h"
#import "XWDNSModel.h"
#import "XWCustomURLProtocol.h"
#import <AFNetworking/AFNetworking.h>

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UITextField *dnsTF;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [XWCustomURLProtocol startMonitor];
}
- (IBAction)btnClick:(UIButton *)sender {
    if (self.dnsTF.text.length <= 0) {
        NSLog(@"请输入DNS");
        return;
    }
    
    [XWDNSModel shared].dns = self.dnsTF.text;
    
    
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    configuration.protocolClasses = @[[XWCustomURLProtocol class]];
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:nil sessionConfiguration:configuration];
    [manager GET:@"http://rap2api.taobao.org/app/mock/86546/mvp" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@", responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"%@", error);
    }];
}


@end
